﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace 无线打分网站.Manage
{
    public partial class EGradeList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.Items.Clear();
                DropDownList2.Items.Clear();
                DropDownList3.Items.Clear();
                DropDownList1.Items.Add("全部");
                DataTable dt = Analysis.GetTeacherList();
                foreach (DataRow dr in dt.Rows)
                {
                    DropDownList1.Items.Add(dr[0].ToString());
                }
                DropDownList2.Items.Add("全部");
                dt = Analysis.GetShiYanList();
                foreach (DataRow dr in dt.Rows)
                {
                    DropDownList2.Items.Add(dr[0].ToString());
                }
                DropDownList3.Items.Add("全部");
                dt = Analysis.GetRoomList();
                foreach (DataRow dr in dt.Rows)
                {
                    DropDownList3.Items.Add(dr[0].ToString());
                }
                TextBox2.Text = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss");
                TextBox1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string t;
            string s;
            string r;
            string stime;
            string eTime;
            if (DropDownList1.SelectedIndex == 0)
                t = "";
            else
                t = DropDownList1.Text;
            if (DropDownList2.SelectedIndex == 0)
                s = "";
            else
                s = DropDownList2.Text;
            if (DropDownList3.SelectedIndex == 0)
                r = "";
            else
                r = DropDownList3.Text;
            stime = TextBox2.Text;
            eTime = TextBox1.Text;
            DataTable dt = Analysis.GetEGradeList(t, s, r, stime, eTime);
            dt.Columns.Add("AverageGrade");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int count = int.Parse(dt.Rows[i]["Grade5"].ToString());
                count += int.Parse(dt.Rows[i]["Grade4"].ToString());
                count += int.Parse(dt.Rows[i]["Grade3"].ToString());
                count += int.Parse(dt.Rows[i]["Grade2"].ToString());
                count += int.Parse(dt.Rows[i]["Grade1"].ToString());
                int sum = int.Parse(dt.Rows[i]["GradeSum"].ToString());
                dt.Rows[i]["AverageGrade"] = ((float)sum/count).ToString("F2");                
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}